# 绘制渔网
from fish import *
from music import *


class FishingNet(pygame.sprite.Sprite):
    def __init__(self) -> None:
        super().__init__()
        self.image = pygame.image.load(r'img/fish_net/blue_net.png').convert_alpha()
        self.rect = self.image.get_rect()
        self.hurt = 1  # 渔网每帧造成的伤害

    def reset(self, bullet):
        self.rect.center = bullet.rect.center
        self.rect.top -= 15

    def collision(self, fishes: pygame.sprite.Group) -> dict:
        """ 判断是否有鱼碰到了网，返回本次击杀鱼后得到的分数 """
        fishes_hit = pygame.sprite.spritecollide(self, fishes, False, pygame.sprite.collide_mask)
        res = {'score': 0, 'kill_manta': 0, 'kill_shark': 0, 'kill_boss': 0}
        for fish in fishes_hit:
            fish.life -= self.hurt
            if fish.life <= 0:
                fish.active = False
                if isinstance(fish, MantaFish):
                    fish_kill_sound.play()
                    res['kill_manta'] += 1
                elif isinstance(fish, SharkFish):
                    fish_kill_sound.play()
                    res['kill_shark'] += 1
                elif isinstance(fish, BossFish):
                    big_fish_kill_sound.play()
                    res['kill_boss'] += 1
                res['score'] += fish.kill_score
        return res


# 加强渔网(由超级子弹弹出)
class SuperFishingNet(FishingNet):
    def __init__(self) -> None:
        super().__init__()
        self.image = pygame.image.load(r'img/fish_net/red_net.png').convert_alpha()
        self.rect = self.image.get_rect()
        self.hurt = 10
